//
//  XLTabBarViewController.swift
//  LaowuquanS
//
//  Created by 王小林 on 2017/7/3.
//  Copyright © 2017年 王小林. All rights reserved.
//

import UIKit

class XLTabBarViewController: UITabBarController {
    
 
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        addChildViewControllers()
        let backView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 49))
        backView.backgroundColor = UIColor.white
        tabBar.insertSubview(backView, at: 0)
        tabBar.isOpaque = true
        
        var attrs = [NSAttributedString.Key: Any]()
        attrs[NSAttributedString.Key.foregroundColor] = kXLNavBarColor
        // 设置tabBar字体颜色
        UITabBarItem.appearance().setTitleTextAttributes(attrs, for: .selected)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /// 添加所有子控制器
    func addChildViewControllers() {
        
        setupOneChildViewController("首页", image: "conventional-icon-Home-gray", selectedImage: "conventional-icon-Home-red", controller: XLWorksViewController.init())
        setupOneChildViewController("新闻", image: "conventional-icon-information-gray", selectedImage: "conventional-icon-information-red", controller: XLNewsViewController.init())
        setupOneChildViewController("信息", image: "conventional-icon-chat-gray", selectedImage: "conventional-icon-chat-red", controller: XLMessageViewController.init())
        setupOneChildViewController("我的", image: "conventional-icon-personal-gray", selectedImage: "conventional-icon-personal-red", controller: XLMineViewController.init())
    }
    
    fileprivate func setupOneChildViewController(_ title: String, image: String, selectedImage: String, controller: UIViewController){
        
        controller.tabBarItem.title = title
        controller.title = title
        controller.view.backgroundColor = kXLBackgroundColor
        controller.tabBarItem.image =  UIImage(named:image)?.withRenderingMode(.alwaysOriginal)
        controller.tabBarItem.selectedImage = UIImage(named:selectedImage)?.withRenderingMode(.alwaysOriginal)
        let naviController = XLNavigationViewController.init(rootViewController: controller)
        addChild(naviController)

    }
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
